package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPhone;
import com.ruoyi.system.service.ISysPhoneService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电话号码信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/system/phone")
public class SysPhoneController extends BaseController
{
    @Autowired
    private ISysPhoneService sysPhoneService;

    /**
     * 查询电话号码信息列表
     */
    @ApiOperation("查询电话号码信息列表")
    @PreAuthorize("@ss.hasPermi('system:phone:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPhone sysPhone)
    {
        startPage();
        List<SysPhone> list = sysPhoneService.selectSysPhoneList(sysPhone);
        return getDataTable(list);
    }

    /**
     * 导出电话号码信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:phone:export')")
    @Log(title = "电话号码信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPhone sysPhone)
    {
        List<SysPhone> list = sysPhoneService.selectSysPhoneList(sysPhone);
        ExcelUtil<SysPhone> util = new ExcelUtil<SysPhone>(SysPhone.class);
        util.exportExcel(response, list, "电话号码信息数据");
    }

    /**
     * 获取电话号码信息详细信息
     */
    @ApiOperation("获取电话号码信息详dasda细信息")
    @PreAuthorize("@ss.hasPermi('system:phone:query')")
    @GetMapping(value = "/{phoneId}")
    public AjaxResult getInfo(@PathVariable("phoneId") Long phoneId)
    {
        return AjaxResult.success(sysPhoneService.selectSysPhoneByPhoneId(phoneId));
    }



    /**
     * 新增电话号码信息
     */
    @PreAuthorize("@ss.hasPermi('system:phone:add')")
    @Log(title = "电话号码信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysPhone sysPhone)
    {
        sysPhone.setCreateBy(getUsername());
        return toAjax(sysPhoneService.insertSysPhone(sysPhone));
    }

    /**
     * 修改电话号码信息
     */
    @PreAuthorize("@ss.hasPermi('system:phone:edit')")
    @Log(title = "电话号码信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPhone sysPhone)
    {
        sysPhone.setUpdateBy(getUsername());
        return toAjax(sysPhoneService.updateSysPhone(sysPhone));
    }

    /**
     * 删除电话号码信息
     */
    @PreAuthorize("@ss.hasPermi('system:phone:remove')")
    @Log(title = "电话号码信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{phoneIds}")
    public AjaxResult remove(@PathVariable Long[] phoneIds)
    {
        return toAjax(sysPhoneService.deleteSysPhoneByPhoneIds(phoneIds));
    }
}
